class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

m = A("m")
f = B("f")
i = A("i")
k = A("k")
g = A("g")
d = B("d")

m.p = f
f.u = d
i.p = f
k.p = f
g.p = d
d.u = f
assert i.p.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

m = A("m")
f = B("f")
i = A("i")
k = A("k")
g = A("g")
d = B("d")

m.p = f
f.u = d
i.p = f
k.p = f
g.p = d
d.u = f
assert i.p.u.u.u.txt == "d"