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

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

g = A("g")
h = B("h")
j = B("j")
f = A("f")
c = A("c")
b = B("b")

g.x = f
g.y = c
h.y = b
h.u = j
j.y = h
j.u = h
f.x = c
f.y = c
c.x = f
c.y = g
b.y = h
b.u = j
assert c.x.y.y.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.y: A = None
        self.txt = txt

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

g = A("g")
h = B("h")
j = B("j")
f = A("f")
c = A("c")
b = B("b")

g.x = f
g.y = c
h.y = b
h.u = j
j.y = h
j.u = h
f.x = c
f.y = c
c.x = f
c.y = g
b.y = h
b.u = j
assert c.x.y.y.y.x.txt == "f"