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

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

j = A("j")
e = B("e")
n = B("n")
g = A("g")
h = B("h")
d = B("d")
c = A("c")

j.y = g
e.u = c
e.y = j
n.u = j
n.y = j
g.y = c
h.u = g
h.y = j
d.u = c
d.y = j
c.y = g
assert e.u.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.u: A = None
        self.y: A = None
        self.txt = txt

j = A("j")
e = B("e")
n = B("n")
g = A("g")
h = B("h")
d = B("d")
c = A("c")

j.y = g
e.u = c
e.y = j
n.u = j
n.y = j
g.y = c
h.u = g
h.y = j
d.u = c
d.y = j
c.y = g
assert e.u.y.y.y.y.txt == "c"