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

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

d = A("d")
h = B("h")
j = A("j")
f = B("f")

d.z = j
d.o = j
h.t = f
h.r = f
j.z = d
j.o = d
f.t = h
f.r = h
assert j.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.o: A = None
        self.txt = txt

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

d = A("d")
h = B("h")
j = A("j")
f = B("f")

d.z = j
d.o = j
h.t = f
h.r = f
j.z = d
j.o = d
f.t = h
f.r = h
assert j.o.o.o.o.txt == "j"