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.z: A = None
        self.x: A = None
        self.txt = txt

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

m.x = g
m.y = b
c.z = f
c.x = b
h.z = g
h.x = f
g.x = b
g.y = b
f.x = b
f.y = b
b.x = f
b.y = m
j.z = b
j.x = g
assert j.x.x.x.y.y.y.y.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.z: A = None
        self.x: A = None
        self.txt = txt

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

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