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

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

a = A("a")
b = B("b")
j = B("j")
f = A("f")

a.o = b
b.y = j
b.r = j
j.y = b
j.r = b
f.o = j
assert j.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

a = A("a")
b = B("b")
j = B("j")
f = A("f")

a.o = b
b.y = j
b.r = j
j.y = b
j.r = b
f.o = j
assert j.r.r.r.txt == "b"