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

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

b = A("b")
j = B("j")
d = A("d")
n = B("n")
c = A("c")
m = B("m")

b.y = d
j.p = d
d.y = b
n.p = c
c.y = d
m.p = b
assert m.p.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

b = A("b")
j = B("j")
d = A("d")
n = B("n")
c = A("c")
m = B("m")

b.y = d
j.p = d
d.y = b
n.p = c
c.y = d
m.p = b
assert m.p.y.y.y.y.y.txt == "d"